package shmged.com.shlcm.objs.persist;

import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import shmged.com.shlcm.fc.CmPersistable;
import shmged.com.shlcm.fc.CmPersistenceHelper;
import wt.fc.ReferenceFactory;
import wt.org.WTUser;
import wt.session.SessionHelper;
import wt.util.WTException;

public class CmReimbursementDetailEntry implements CmPersistable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 
	 */
	/**
	 * 
	 */
	public static final String CMKEYID="cmKeyId";
	public static final String CMUSERNAME="cmUserName";
	public static final String CMCLASSMASTERKEY="cmClassMasterKey";
	public static final String CMIDMASTER="cmIdMaster";
	public static final String CMDETAILTYPE="cmDetailType";
	public static final String CMDETAILAMOUNT="cmDetailAmount";
	public static final String CMDETAILTO="cmDetailTo";
	public static final String CMDETAILTIME="cmDetailTime";
	public static final String CMDETAILDESC="cmDetailDesc";
	public static final String CMCREATETIME="cmCreateTime";
	public static final String CMMODIFYTIME="cmModifyTime";

	private String  keyId ;      			
	private String  cmUserName;         		
	private String  cmClassMasterKey;            
	private String  cmIdMaster;				
	private String  cmDetailType;				
	private double  cmDetailAmount;	
	private String  cmDetailTo;				
	private Timestamp   cmDetailTime;					
	private String  cmDetailDesc;			   
	private Timestamp cmCreateTime;
	private Timestamp cmModifyTime;	
	
	
	public CmReimbursementDetailEntry(){};	
	public static CmReimbursementDetailEntry createCmReimbursementDetailEntry(Map map)
	{
		CmReimbursementDetailEntry crde=null;
		ReferenceFactory fc=new ReferenceFactory();
		try {
			WTUser user=(WTUser)SessionHelper.manager.getPrincipal();
			crde=new CmReimbursementDetailEntry(map.get("classMasterKey").toString(),map.get("oid").toString().trim(),map.get("detailType").toString()
					,map.get("detailAmount").toString(),map.get("detailTo").toString(),map.get("detailTime").toString(),map.get("detailDesc").toString());
		} catch (WTException e) {
			e.printStackTrace();
		}
		return crde;
		
	}
	
	
	public CmReimbursementDetailEntry(String cmClassMasterKey,String cmIdMaster,String cmDetailType,String cmDetailAmount,
			String cmDetailTo,String cmDetailTime,String cmDetailDesc)
	{
		super();
		 Timestamp time = Timestamp.valueOf(cmDetailTime+" 09:00:00.0");
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
		this.keyId=generateKeyId();
		this.cmClassMasterKey=cmClassMasterKey;
		this.cmIdMaster=cmIdMaster;
		this.cmDetailType=cmDetailType;
		this.cmDetailAmount=Double.parseDouble(cmDetailAmount);
		this.cmDetailTo=cmDetailTo;
		this.cmDetailTime=time;
		this.cmDetailDesc=cmDetailDesc;
	}
	

	public void setKeyId(String keyId) {
		this.keyId = keyId;
	}
	private String generateKeyId(){
		return CmPersistenceHelper.genUniquedId();
	}
	
	public String getCmUserName() {
		return cmUserName;
	}

	public void setCmUserName(String cmUserName) {
		this.cmUserName = cmUserName;
	}

	public String getCmClassMasterKey() {
		return cmClassMasterKey;
	}

	public void setCmClassMasterKey(String cmClassMasterKey) {
		this.cmClassMasterKey = cmClassMasterKey;
	}

	public String getCmIdMaster() {
		return cmIdMaster;
	}

	public void setCmIdMaster(String cmIdMaster) {
		this.cmIdMaster = cmIdMaster;
	}

	public String getCmDetailType() {
		return cmDetailType;
	}

	public void setCmDetailType(String cmDetailType) {
		this.cmDetailType = cmDetailType;
	}



	public String getCmDetailTo() {
		return cmDetailTo;
	}

	public void setCmDetailTo(String cmDetailTo) {
		this.cmDetailTo = cmDetailTo;
	}

	public Timestamp getCmDetailTime() {
		return cmDetailTime;
	}

	public void setCmDetailTime(Timestamp cmDetailTime) {
		this.cmDetailTime = cmDetailTime;
	}

	public String getCmDetailDesc() {
		return cmDetailDesc;
	}

	public void setCmDetailDesc(String cmDetailDesc) {
		this.cmDetailDesc = cmDetailDesc;
	}

	public Timestamp getCmCreateTime() {
		return cmCreateTime;
	}

	public void setCmCreateTime(Timestamp cmCreateTime) {
		this.cmCreateTime = cmCreateTime;
	}

	public Timestamp getCmModifyTime() {
		return cmModifyTime;
	}

	public void setCmModifyTime(Timestamp cmModifyTime) {
		this.cmModifyTime = cmModifyTime;
	}



	
	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Map getCreateMap() {
		Timestamp now = new Timestamp(new Date().getTime());
		 HashMap ret = new HashMap();
		 ret.put(CMKEYID, keyId);
		 ret.put(CMUSERNAME, cmUserName);
		 ret.put(CMCLASSMASTERKEY, cmClassMasterKey);
	     ret.put(CMIDMASTER, cmIdMaster);
	     ret.put(CMDETAILTYPE, cmDetailType);
	     ret.put(CMDETAILAMOUNT, cmDetailAmount);
	     ret.put(CMDETAILTO, cmDetailTo);
	     ret.put(CMDETAILTIME, cmDetailTime);
	     ret.put(CMDETAILDESC, cmDetailDesc);
	     ret.put(CMCREATETIME, now);
	     ret.put(CMMODIFYTIME, now);
		return ret;
	}
	@Override
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("cmUserName :"+cmUserName);
		sb.append("cmClassMasterKey :"+cmClassMasterKey);
		sb.append("cmIdMaster :"+cmIdMaster);
		sb.append("cmDetailType :"+cmDetailType);
		sb.append("cmDetailAmount :"+cmDetailAmount);
		sb.append("cmDetailTo :"+cmDetailTo);
		sb.append("cmDetailTime :"+cmDetailTime);
		sb.append("cmDetailDesc :"+cmDetailDesc);
		return sb.toString();
	}
	

	public double getCmDetailAmount() {
		return cmDetailAmount;
	}


	public void setCmDetailAmount(double cmDetailAmount) {
		this.cmDetailAmount = cmDetailAmount;
	}


	public CmPersistable getObject(ResultSet rs) throws Exception {
		 if (rs != null) {
	         setKeyId(rs.getString(CMKEYID));
	         setCmUserName(rs.getString(CMUSERNAME));         		
	         setCmClassMasterKey(rs.getString(CMCLASSMASTERKEY));            
	         setCmIdMaster(rs.getString(CMIDMASTER));				
	         setCmDetailType(rs.getString(CMDETAILTYPE));				
	         setCmDetailAmount(rs.getDouble(CMDETAILAMOUNT));	
	         setCmDetailTo(rs.getString(CMDETAILTO));				
	         setCmDetailTime(rs.getTimestamp(CMDETAILTIME));					
	         setCmDetailDesc(rs.getString(CMDETAILDESC));			   
	         setCmCreateTime(rs.getTimestamp(CMCREATETIME));
	         setCmModifyTime(rs.getTimestamp(CMMODIFYTIME));	
	      }
	      return this;
	}
	
	

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Map getUpdateMap() {
		Timestamp now = new Timestamp(new Date().getTime());
		 HashMap ret = new HashMap();
	     ret.put(CMMODIFYTIME, now);
	     ret.put(CMDETAILTYPE, cmDetailType);
	     ret.put(CMDETAILAMOUNT, cmDetailAmount);
	     ret.put(CMDETAILTO, cmDetailTo);
	     ret.put(CMDETAILTIME, cmDetailTime);
	     ret.put(CMDETAILDESC, cmDetailDesc);
		return ret;
	}


	@Override
	public Object getKeyId() {
		return keyId;
	}
	
	

}
